package com.elderly.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Transaction;

import javax.annotation.Resources;

/**
 * @Description redis 连接
 * @Date 2021/10/5 16:35
 * @Created 30500
 */
@Configuration
@PropertySource("classpath:redisConfig.properties")
public class RedisConfig {
    /**
     * ip 地址
     */
    @Value("${redis.host}")
    private String host;
    /**
     * 开放端口
     */
    @Value("${redis.port}")
    private Integer port;

    /**
     * 集群redis池
     */
    @Bean(name = "jedisPool")
    public JedisPool jedisPool() {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(30);
        config.setMaxIdle(10);
        JedisPool jedisPool = new JedisPool(config, host, port);
        return jedisPool;
    }

    /**
     * 单节点redis连接
     */
    @Bean(name = "jedis")
    public Jedis jedis() {
        return new Jedis(host, port);
    }

}
